package com.example.service;


import com.example.entity.Message;
import com.example.repository.MessageRepository;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.List;

@Service
@RequiredArgsConstructor
@Validated
public class MessageService {
    private final MessageRepository messageRepository;

    public List<Message> getAll() {
        return (List<Message>) messageRepository.findAll();
    }

    public Message createMessage(@NotNull String message) {
        Message messages = Message.builder().message(message).build();
        return messageRepository.save(messages);
    }
}
